﻿<template>
  <div>
    <div v-show="!modifyEntity.showModify && !modifyEntity.showDetail">
      <!--查询参数-->
      <params ref="params" @handleRefresh="handleRefresh" :loading="loading"></params>
      <!--表格页面-->
      <my-table ref="myTable" title="项目列表" :columns="columns" :loading="loading" :dataSource="dataSource" @loadData="loadData" @handleAdd="handleAdd" @removeSubmit="removeSubmit" @handleEdit="handleEdit" @handleImport="handleImport" @handleExport="handleExport" @handleDetail="handleDetail" addAction="project_create" deleteAction="project_delete" editAction="project_edit" detailAction="project_details">
        <template slot="icon" slot-scope="{ text }">
          <img @click="showImg(text.record.icon)" v-if="text.record.icon" width="50" style="cursor: pointer" height="50" :src="text.record.icon" />
        </template>
      </my-table>

      <a-modal :visible="previewVisible" :footer="null" @cancel="handleClosePreview">
        <img alt="收款二维码" style="width: 100%" :src="previewImg" />
      </a-modal>
    </div>
    <!--修改页面-->
    <modify v-if="modifyEntity.showModify" @handleRefresh="handleRefresh" :modifyEntity="modifyEntity" />
    <detail v-if="modifyEntity.showDetail" @handleRefresh="handleRefresh" :modifyEntity="modifyEntity" />
  </div>
</template>
<script>
import modify from "./modify";
import detail from "./detail";
import myTable from "_c/myTable/index";
import params from "./components/params";
import { projectColumns, queryProjectPage, deleteProject } from "./project";

export default {
  name: "Project",
  components: { params, modify, detail, myTable },
  data() {
    return {
      modifyEntity: {
        // 传递的主键
        id: "",
        // 页面操作类型
        operation: "",
        // 是否展示编辑页面
        showModify: false,
        // 是否展示详情页面
        showDetail: false,
        // 标题
        title: "",
      },
      // 加载动画
      loading: false,
      // 绑定的数据源
      dataSource: [],
      // 表格绑定的列
      columns: projectColumns,
      previewVisible: false,
      previewImg: "",
    };
  },
  mounted() {
    this.loadData();
  },
  methods: {
    //#region 查看图片
    showImg(img) {
      this.previewImg = img;
      this.previewVisible = true;
    },
    handleClosePreview() {
      this.previewImg = "";
      this.previewVisible = false;
    },
    //#endregion
    //#region 查询列表
    // 保存/修改后刷新表格
    handleRefresh() {
      this.modifyEntity.showDetail = false;
      this.modifyEntity.showModify = false;
      this.$refs.myTable.pagination.current = 1;
      this.loadData();
    },
    // 加载数据
    loadData() {
      this.loading = true;
      let that = this;
      let queryParams = {
        ...this.$refs.params.params,
        current: this.$refs.myTable.pagination.current,
        pageSize: this.$refs.myTable.pagination.pageSize,
      };
      queryProjectPage(queryParams)
        .then((res) => {
          let { data, totalCount } = res.data;
          that.dataSource = data;
          this.$refs.myTable.pagination.total = totalCount;
          that.loading = false;
        })
        .catch(() => {
          that.loading = false;
        });
    },
    //#endregion

    //#region 添加
    // 打开添加页面
    handleAdd() {
      this.modifyEntity = {
        showModify: true,
        showDetail: false,
        title: "新增项目租户",
        operation: this.operationFlag.Add,
      };
    },
    //#endregion

    //#region 删除
    // 删除
    removeSubmit(ids) {
      deleteProject(ids).then((res) => {
        if (res.code == 200) {
          this.$notification.success({ description: res.msg });
          this.handleRefresh();
        } else {
          this.$notification.error({ description: res.msg });
        }
      });
    },
    //#endregion

    //#region 修改
    // 打开编辑页面
    handleEdit(item) {
      this.modifyEntity = {
        id: item.id,
        showModify: true,
        showDetail: false,
        title: "修改项目租户",
        operation: this.operationFlag.Edit,
      };
    },
    //#endregion

    //#region 详情
    // 打开详情页面
    handleDetail(item) {
      this.modifyEntity = {
        id: item.id,
        showDetail: true,
        showModify: false,
        title: "项目租户详情",
        operation: this.operationFlag.Detail,
      };
    },
    //#endregion

    //#region 导入
    // 导入数据
    handleImport() { },
    //#endregion

    //#region 导出
    // 导出数据
    handleExport() { },
    //#endregion
  },
};
</script>
